﻿namespace com.crownpack.Extensions.SharePointExtensions
{
    using Microsoft.SharePoint;

    public static class SPUserExtensions
    {
        #region Methods

        /// <summary>
        /// Returns a Boolean value that specifies whether the user is a member of the specified group.
        /// </summary>
        /// <param name="spUser"></param>
        /// <param name="id">A 32-bit integer that specifies the group identifier (ID).</param>
        /// <returns>true if the user is a member of the group; otherwise, false.</returns>
        public static bool IsMemberOfGroup( this SPUser spUser, int id )
        {
            return spUser.Groups.GetByID( id ) != null;
        }

        /// <summary>
        /// Returns a Boolean value that specifies whether the user is a member of the specified group.
        /// </summary>
        /// <param name="spUser"></param>
        /// <param name="spGroup">A group on a Windows SharePoint Services Web site.</param>
        /// <returns>true if the user is a member of the group; otherwise, false.</returns>
        public static bool IsMemberOfGroup( this SPUser spUser, SPGroup spGroup )
        {
            return spUser.Groups.GetByID( spGroup.ID ) != null;
        }

        #endregion Methods
    }
}